<?php

class Application_Form_Dodajtresc extends Zend_Form {

    public function init() {

        $content = new Zend_Form_Element_Textarea('content', array(
                    'label' => 'Treść',
                    'class' => 'content-add'
                ));
        $content->setRequired(true);

        $title = new Zend_Form_Element_Text('title', array(
                    'label' => 'Tytuł',
                ));
        $title->setRequired(true);

        $y = date("Y", time());
        $m = date("m", time());
        $d = date("d", time());

        $path = APPLICATION_PATH . '/../public/files';

        $path .= '/' . $y . '';
        if (!file_exists($path))
            mkdir($path);
        $path .= '/' . $m . '';
        if (!file_exists($path))
            mkdir($path);
        $path .= '/' . $d;
        if (!file_exists($path))
            mkdir($path);

        $img = new Zend_Form_Element_File('image',
                        array());
        $img->setLabel('Upload an image:')
                ->setDestination(realpath(realpath($path)));

// ensure only 1 file
        $img->addValidator('Count', false, 1);
// limit to 100K
        $img->addValidator('Size', false, 102400);
// only JPEG, PNG, and GIFs
        $img->addValidator('Extension', false, 'jpg,png,gif');
        $img->setValueDisabled(true);
        $img->addValidator('Size', false, 102400 * 10);

        $this->addDisplayGroup(array(
            $title, $content, //$img
                ), 'gr-main');

        $this->setAttrib('enctype', 'multipart/form-data');

        $submit = new Zend_Form_Element_Submit('submit', array(
                    'label' => 'Dodaj',
                    'class' => 'ui-form-button'
                ));

        $back = new Zend_Form_Element_Button('back', array(
                    'label' => 'Powrót',
                    'class' => 'ui-form-button goback'
                ));
        $back->setDecorators(array('ViewHelper'));
        $submit->setDecorators(array('ViewHelper'));

        $this->addDisplayGroup(array(
            $submit
                ), 'gr-submit', array(
            'order' => 999,
            'class' => 'dodajtresc'
        ));
    }

}

